<?php

namespace app\controller\api;

use app\BaseController;
use think\facade\Cache;
use think\response\Json;

class Order extends BaseController
{
    public function lst()
    {
        return $this->success($this->app->make(\app\model\Order::class)->lst());
    }

    public function getCode(): Json
    {
        return $this->success($this->app->make(\app\model\Order::class)->checkMobile());
    }

    public function checkCode(): Json
    {
        if (!$this->request->isPost()) throw new \Exception("请求方式错误", 74001);
        $param = $this->request->post();
        $code = Cache::get("sms_{$param['mobile']}_code");
        if (empty($code)) throw new \Exception("验证码已过期", 74002);
        if ($code != $param['code']) throw new \Exception("验证码错误", 74003);
        return $this->lst();
    }

    public function orderDetail(): Json
    {
        return $this->success($this->app->make(\app\model\Order::class)->detail());
    }
}
